package concurrentAPI;

public class SequenceGeneratorExample extends Thread {

	private static SequenceGenerator generator = new SequenceGenerator();
	
	@Override
	public void run() {
		while (!isInterrupted()) {
			try {
				long nextValue = generator.next();
				System.out.printf("Thread %s: next value = %d\n", 
					this.getName(), nextValue);
				Thread.sleep((long)(Math.random() * 1000));	
			} catch (InterruptedException ie) {
				break;
			}			
		}		
	}

	public static void main(String[] args) {
		Thread t1 = new SequenceGeneratorExample();
		t1.start();
		Thread t2 = new SequenceGeneratorExample();
		t2.start();
		Thread t3 = new SequenceGeneratorExample();
		t3.start();
	}

}
